/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.easoftware.code.beans.maintenance;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Eliu
 */
public class DataTableRowCell implements Comparable<DataTableRowCell>, Serializable {

    private String title;
    private Object value;
    private DataTableRow parent;
    private Integer listIndex;
    private String attribute;
    private boolean show = false;

    public DataTableRowCell(DataTableRow parent) {
        this.parent = parent;
    }

    public void doBind() {
        try {
            if (this.value == null) {
                Object source = parent.getListBinded().get(listIndex);
                Method method = source.getClass().getMethod("get" + String.valueOf(attribute.charAt(0)).toUpperCase().concat(attribute.substring(1)), new Class[]{});
                this.value = method.invoke(source, new Object[]{});
            }
        }
        catch (Exception ex) {
            Logger.getLogger(DataTableRowCell.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public boolean isShow() {
        return show;
    }

    public void setShow(boolean show) {
        this.show = show;
    }

    public Integer getListIndex() {
        return listIndex;
    }

    public void setListIndex(Integer listIndex) {
        this.listIndex = listIndex;
    }

    public String getAttribute() {
        return attribute;
    }

    public void setAttribute(String attribute) {
        this.attribute = attribute;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }

    public DataTableRow getParent() {
        return parent;
    }

    public void setParent(DataTableRow parent) {
        this.parent = parent;
    }

    @Override
    public int compareTo(DataTableRowCell o) {
        return o.getListIndex().compareTo(listIndex);
    }

    @Override
    public int hashCode() {
        int hash = 3;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final DataTableRowCell other = (DataTableRowCell) obj;
        if (this.listIndex != other.listIndex && ( this.listIndex == null || !this.listIndex.equals(other.listIndex) )) {
            return false;
        }
        return true;
    }
}
